﻿using System;

namespace LearnBaseAndThis
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Father f = new Father();
            f.DoSomething();

            Console.WriteLine("------------------------");

            Son s = new Son();
            s.DoSomething();

            Console.WriteLine("------------------------");

            Daughter d = new Daughter();
            d.DoSomething();

            Console.WriteLine("------------------------");

            double j = 2;
            Console.WriteLine(j.ToDollar(7).ToString());  //14
            Console.WriteLine(j.ToDollar().ToString());   //12

            Console.ReadKey();
        }
    }

    class Father
    {
        public Father()
        {
            Console.WriteLine($"{nameof(Father)}.构造函数");
        }

        public Father(string name)
        {
            Console.WriteLine($"{nameof(Father)}.构造函数,Name={name}");
        }

        public virtual void DoSomething()
        {
            Console.WriteLine($"{nameof(Father)}.Work");
        }
    }

    class Son : Father
    {
        public Son() : this("萝卜")
        {
            Console.WriteLine($"{nameof(Son)}.构造函数");
        }

        public Son(string name)
        {
            Console.WriteLine($"{nameof(Son)}.构造函数,Name={name}");
        }

        public override void DoSomething()
        {
            Console.WriteLine($"{nameof(Son)}.Learn");
        }
    }

    class Daughter : Father
    {
        public Daughter() : base("大萝卜")
        {
            Console.WriteLine($"{nameof(Son)}.构造函数");
        }

        public override void DoSomething()
        {
            Console.WriteLine($"{nameof(Daughter)}.Play");
        }
    }

    public static class Extension
    {
        public static double ToDollar(this double i)
        {
            return ToDollar(i, 6);
        }

        public static double ToDollar(this double i, int j)
        {
            return i *= j;
        }
    }
}
